Vue.directive('enterNumber', {
    inserted: function (el) {
        el.addEventListener("keypress",function(e){
            e = e || window.event
            let charcode = typeof e.charCode === 'number' ? e.charCode : e.keyCode
            let re = /\d/
            if(!re.test(String.fromCharCode(charcode)) && charcode > 9 && !e.ctrlKey){
                if(e.preventDefault){
                    e.preventDefault()
                }else{
                    e.returnValue = false
                }
            }
        })
    }
})



function initVue(opts) {

    new Vue({
        el: '#app',
        data: function() {
            return {

                prefix: opts.prefix,
                title: opts.title,
                list: [],
                pkgid: opts.pkgid

            }
        },

        mounted() {
                this.getPackages()
        },

        methods: {

            goPkgIntro(e){opts.goPkgIntro(e, this)},

            goMini(wx) {opts.goMini(wx, this)},

            getPackages() {
                let that = this
                axios.get('/pkg/benefit/package/list')
                    .then(res => {
                         that.list = res.data
                    })
            }

        }

    })

}